<?php
error_reporting(E_ALL|E_STRICT);
ini_set('display_errors', 1);

date_default_timezone_set('Europe/Paris');
define('APPLICATION_PATH', realpath(dirname(__FILE__)));

set_include_path(implode(PATH_SEPARATOR, array(
	realpath(APPLICATION_PATH . '/lib'),
	'.'
))); 

if (!defined('APPLICATION_ENV')) {
	define('APPLICATION_ENV', getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production');
}

// chargement des classes
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->setFallbackAutoloader(true);

// Chargement de la configuration
$config = new Zend_Config_Ini('./conf/config.ini', 'devlopment');
$registry = Zend_Registry::getInstance();
$registry->set('config', $config);


// Mise en place de la BDD
$db = Zend_Db::factory($config->db);
Zend_Db_Table::setDefaultAdapter($db);

// setup controller
$frontController = Zend_Controller_Front::getInstance();
$frontController->throwExceptions(true);
$frontController->setControllerDirectory('./application/controllers');
Zend_Layout::startMvc(array('layoutPath'=>'./application/layouts'));

// Set routeur REST
$restRoute = new Zend_Rest_Route($frontController);
$frontController->getRouter()->addRoute('default', $restRoute);

// initialize roles
/*$acl = new Zend_Acl();
 
$acl->addRole(new Zend_Acl_Role('guest'))
    ->addRole(new Zend_Acl_Role('member'))
    ->addRole(new Zend_Acl_Role('admin'));
 
$acl->addResource(new Zend_Acl_Resource('gugus'));
$acl->addResource(new Zend_Acl_Resource('coloc'));
$acl->addResource(new Zend_Acl_Resource('admin:create','admin'));
 
//$acl->deny('guest', 'someResource');
$acl->deny();
//$acl->allow('guest', 'someResource');
//$acl->allow('member', null, array('someResource1', 'someResource2', 'someResource3'));
//$acl->allow('admin');
 
$frontController->registerPlugin(new Zend_Controller_Plugin_Acl($acl, 'guest')); 
*/

// run
$frontController->dispatch();
